package com.itcast.yygh.oss.controller;

import com.itcast.common.result.R;
import com.itcast.yygh.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 文件上传
 */
@Api("图片上传")
@RestController
@RequestMapping("/admin/oss/file")
public class OssController {

    @Resource
    private OssService ossService;

    //上传文件
    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public R upload(@ApiParam(name = "file", value = "文件", required = true)
                    @RequestParam("file") MultipartFile file){
        String filePath = ossService.upload(file);
        return R.ok().message("文件上传成功!").data("url",filePath);
    }
}
